package com.example.lin.entity.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 
 * </p>
 *
 * @author 林志豪
 * @since 2024-02-08
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@TableName("sys_user")
@ApiModel(value = "User对象", description = "用户实例")
public class User implements UserDetails, Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("用户ID")
    @TableId(value = "user_id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("用户姓名")
    @TableField(value = "user_name")
    private String name;

    @ApiModelProperty("用户账号")
    @TableField("user_username")
    private String username;

    @ApiModelProperty("用户密码")
    @TableField("user_password")
    private String password;

    @ApiModelProperty("用户电话")
    @TableField("user_phone")
    private String phone;

    @ApiModelProperty("用户性别(0-男，1-女)")
    @TableField("user_gender")
    private Integer gender;

    @ApiModelProperty("用户昵称")
    @TableField("user_nickname")
    private String nickname;

    @ApiModelProperty("用户邮箱")
    @TableField("user_email")
    private String email;

    @ApiModelProperty("所属部门ID")
    private Integer departmentId;

    @ApiModelProperty("是否锁定")
    private Integer locked;

    @ApiModelProperty("是否删除")
    private Integer deleted;

    @ApiModelProperty("账号是否过期(0-已过期，1-未过期)")
    @TableField(exist = false)
    private boolean usernameExpired = true;

    @ApiModelProperty("密码是否过期(0-已过期，1-未过期)")
    @TableField(exist = false)
    private boolean passwordExpired = true;

    @ApiModelProperty("是否可用(0-不可用，1-可用)")
    @TableField(exist = false)
    private boolean enabled = true;

    @ApiModelProperty("是否为管理员(0-否，1-超级管理员，2-普通管理员)")
    @TableField(exist = false)
    private boolean isAdmin = true;

    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("修改时间")
    private Date updateTime;

    @ApiModelProperty("用户角色")
    @TableField(exist = false)
    private List<Role> roles;

    @ApiModelProperty("权限列表")
    @TableField(exist = false)
    Collection<? extends GrantedAuthority> authorities;

    @ApiModelProperty("用户权限列表")
    @TableField(exist = false)
    private List<Permission> permissions;

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }
}
